﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SSE657.BahMap.Common
{
    public static class ExtensionMethods
    {
        public static void InverseSort<T>(this List<T> me, IComparer<T> comparer)
        {
            // TODO: Refactor to directly implement inverted QuickSort

            me.Sort(comparer);
            for (int i = 0; i < me.Count / 2; i++)
            {
                int p = me.Count - i - 1;
                T temp = me[i];
                me[i] = me[p];
                me[p] = temp;
            }
        }

        public static int GetCount<T>(this IEnumerable<T> me)
        {
            int i = 0;
            foreach (T t in me)
                i++;
            return i;
        }

        public static void Raise(this EventHandler me, object sender, EventArgs args)
        {
            if (me != null)
                me(sender, args);
        }

        public static void Raise<T>(this EventHandler<T> me, object sender, T args) where T : EventArgs
        {
            if (me != null)
                me(sender, args);
        }
    }
}
